package design.Day01;

import design.Day01.behavior.FlyBehavior;
import design.Day01.behavior.QuackBehavior;

/**
* @description: 鸭子基类，封装公用的方法
* @author: wangjun
* @create: 2022-01-07
*/
public abstract class Duck {

    FlyBehavior flyBehavior;
    QuackBehavior quackBehavior;

    /**
     * 鸭子会游泳
    */
    void swim(){

    }

    /**
     * 鸭子的外观
     */
    abstract void display();

    /**
     * 鸭子飞行
     */
    public void performFly(){
        flyBehavior.fly();
    }

    /**
     * 鸭子叫声
     */
    public void performQuack(){
        quackBehavior.quack();
    }

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }
}
